<?php

	$user = $controller->getCurrentUser();

	if (($user->isAllowedTo(GRADE_ADD_MEMBER) && $user->getGrade()->getType() >= GRADE_TYPE_POWER ))
	{
	
		$showEditView = true;
			
		$userId = intval($request->getParam('id'));

		if ($userId)
		{
			if ($userId != 0)
			{
				$userToChange = user::singleton($userId);
				
				if ($request->getMethod() == 'POST')
				{
					try
					{				
						$gradeId = intval($request->getParam('grade'));
						$comment = $request->getParam('comment');
						$paid = $request->getParam('paid') ? true : false;
						$deposit = $request->getParam('deposit') ? true : false;
						
						$userToChange->setGrade($gradeId);
						$userToChange->setComment($comment);
						$userToChange->setPaid($paid);
						$userToChange->setDeposit($deposit);
						
						$userToChange->update();
						
						logPermactions($user->getId(),'Utilisateur modifi&eacute; : '.$userToChange->getCompleteName());
						
						$controller->addInformation('Modifications effectu&eacute;es.');
						$showEditView = false;
					}
					catch (Exception $e)
					{
						$e->_log();
						$controller->addError('Erreur : Les modifications n\'ont pas pu &ecirc;tre effectu&eacute;es.');
					}
				}
			}
		}
		else
		{
			$showEditView = false;
		}

		// Affichage de la vue
		$controller->setVar('action', $action);
		if ($showEditView)
		{
			$controller->setVar('formIds', array('edit_user_form'));
			$controller->setVar('userToChange', $userToChange);
			$controller->setVar('user', $user);
			$controller->render('editUser');
		}
		else
		{
			$controller->setVar('userList', user::getUserListByGradeType(1));
			$controller->setVar('user',$user);
			$controller->render('searchUser');
		}
	}
	else
		$controller->render('errorRights');
	
?>